var wPlugin = {
  windList: { // 17以上都标记为超强台风
    '0': '无风',
    '1': '软风',
    '2': '轻风',
    '3': '微风',
    '4': '和风',
    '5': '清风',
    '6': '强风',
    '7': '劲风',
    '8': '大风',
    '9': '烈风',
    '10': '狂风',
    '11': '暴风',
    '12': '台风',
    '13': '台风',
    '14': '强台风',
    '15': '强台风',
    '16': '超强台风',
    '17': '超强台风'
  },
  airQual: { // 空气质量
    '0': '无',
    '50': '优',
    '100': '良好',
    '150': '轻度污染',
    '200': '中度污染',
    '250': '重度污染',
    '300': '严重污染'
  },
  weatherList: [
    {text: '晴', icon: '/res/framework/icons/forecast/forecast1.png'},
    {text: '多云', icon: '/res/framework/icons/forecast/forecast2.png'},
    {text: '阴', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '阵雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '雷阵雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '雷阵雨并伴有冰雹', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '雨夹雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '小雨', icon: '/res/framework/icons/forecast/forecast4.png'},
    {text: '中雨', icon: '/res/framework/icons/forecast/forecast4.png'},
    {text: '大雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '暴雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '大暴雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '特大暴雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '阵雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '小雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '中雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '大雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '暴雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '雾', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '冻雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '沙尘暴', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '小雨-中雨', icon: '/res/framework/icons/forecast/forecast4.png'},
    {text: '中雨-大雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '大雨-暴雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '暴雨-大暴雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '大暴雨-特大暴雨', icon: '/res/framework/icons/forecast/forecast5.png'},
    {text: '小雪-中雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '中雪-大雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '大雪-暴雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '浮沉', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '扬沙', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '强沙尘暴', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '飑', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '龙卷风', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '弱高吹雪', icon: '/res/framework/icons/forecast/forecast6.png'},
    {text: '轻霾', icon: '/res/framework/icons/forecast/forecast7.png'},
    {text: '霾', icon: '/res/framework/icons/forecast/forecast7.png'},
  ],
  init: function (map, city, _cb) { // city 参数可以传cityCode或者城市名 cityCode最好，唯一性 焦作市 410800
    var _o = this;
    map.plugin('AMap.Weather', function() {
      var weather = new AMap.Weather(); //创建天气查询实例
      weather.getLive(city, function(err, data) { //执行实时天气信息查询
        if (data) { // 有数据返回
          //console.log('test');
          _cb(_o.htmlInit(data));
        }
      });
    });
  },
  htmlInit: function (res) { // 一天的
    var _o = res;
    var _b = this;  
    this.weatherList.map(function (item) {
      if (item.text == _o.weather) {
        _o.weatherIcon = item.icon;
      }
    })
    var _keys = Object.keys(this.airQual);
    var result = _keys.filter(function (item, index) { return parseInt(_o.humidity) <= parseInt(item) && parseInt(_o.humidity) > parseInt(_keys[index - 1])});
    if (!result) {
      _o.airQualText = '严重污染'
    } else {
      _o.airQualText = this.airQual[result];
    }
    if(isNaN(_o.windPower)){
    	 _o.windPowerText = this.windList['3'];
    }else{
    	 _o.windPowerText = this.windList[_o.windPower];
    }
    return _o;
  },
  dayOrNight: function () { // 当前时间是白天还是黑夜, 早晚6点表示黑夜
    var _date = new Date();
    if (_date.getHours() < 6 || _date.getHours() >= 18) {
      return '晚上';
    } else {
      return '白天';
    }
  },
  returnDate: function (_timePrefix, _datePrefix) { // 日期格式返回, 参数为时间拼接字符串和日期拼接字符串
    var _d = new Date();
    var _time = [
      _d.getHours() >= 10 ? _d.getHours() : '0' + _d.getHours(),
      _timePrefix,
      _d.getMinutes() >= 10 ? _d.getMinutes() : '0' + _d.getMinutes(),
      _timePrefix,
      _d.getSeconds() >= 10 ? _d.getSeconds() : '0' + _d.getSeconds()
    ].join('');
    var _date = [
      _d.getFullYear(),
      _datePrefix,
      (_d.getMonth() + 1 ) >= 10 ? (_d.getMonth() + 1) : '0' + (_d.getMonth() + 1),
      _datePrefix,
      _d.getDate() >= 10 ? _d.getDate() : '0' + _d.getDate()
    ].join('');
    return {
      time: _time,
      date: _date
    }
  }
}